/*
 * Copyright (C) 2018 Logos Technology Ltd.
 */

package com.logos.common.source.network;

import java.util.Map;

import io.reactivex.Observable;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.http.Body;
import retrofit2.http.DELETE;
import retrofit2.http.GET;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.PUT;
import retrofit2.http.PartMap;
import retrofit2.http.QueryMap;
import retrofit2.http.Url;

/**
 * @author Young Ken
 */

public interface BaseServerApi {

    /**
     * post network request
     *
     * @param url   path
     * @param route RequestBody
     * @return Observable
     */
    @POST
    Observable<ResponseBody> post(@Url String url, @Body RequestBody route);

    /**
     * get network request
     *
     * @param url url
     * @return Observable
     */
    @GET
    Observable<ResponseBody> get(@Url String url);

    /**
     * get network request
     *
     * @param url    url
     * @param params map
     * @return Observable
     */
    @GET
    Observable<ResponseBody> get(@Url String url,
                                 @QueryMap Map<String, Object> params);

    /**
     * 下载文件
     *
     * @param url url
     * @return Observable
     */
    @GET
    Observable<ResponseBody> download(@Url String url);

    /**
     * post network request
     *
     * @param url    url
     * @param params Map
     * @return Observable
     */
    @Multipart
    @POST
    Observable<ResponseBody> upload(@Url String url,
                                    @PartMap() Map<String, RequestBody> params);

    /**
     * post network request
     *
     * @param url    url
     * @param params Map
     * @param body   Map
     * @return Observable
     */
    @Multipart
    @POST
    Observable<ResponseBody> upload(@Url String url,
                                    @PartMap() Map<String, RequestBody> params,
                                    @PartMap() Map<String, RequestBody> body);

    /**
     * get network request
     *
     * @param fileUrl url
     * @return Observable
     */
    @GET
    Observable<ResponseBody> downloadFile(@Url String fileUrl);

    /**
     * put net request
     *
     * @param url  url
     * @param body body
     * @return Observable
     */
    @PUT
    Observable<ResponseBody> put(
            @Url String url,
            @Body RequestBody body);

    /**
     * delete net request
     *
     * @param url url
     * @return Observable of request
     */
    @DELETE
    Observable<ResponseBody> delete(@Url String url);

    /**
     * delete network request
     *
     * @param url    url
     * @param params map
     * @return Observable
     */
    @DELETE
    Observable<ResponseBody> delete(@Url String url,
                                    @QueryMap Map<String, Object> params);
}
